package com.dx.mes.service.process.service;

import static com.dx.mes.common.bean.def.GenericDef.ACTION_FLG_INQUIRE;
import static com.dx.mes.common.bean.def.GenericDef.E_BIS_OPE;
import static com.dx.mes.common.bean.def.GenericDef.E_BIS_TOOL_GR;
import static com.dx.mes.common.bean.def.GenericDef.E_READ_NOT_FOUND;
import static com.dx.mes.common.bean.def.GenericDef.E_RET_BOX;
import static com.dx.mes.common.bean.def.GenericDef.E_FPPIWIPEQ_INVALID_BOX_STAT;
import static com.dx.mes.common.bean.def.GenericDef.E_FPPIWIPEQ_INVALID_INPUT;
import static com.dx.mes.common.bean.def.GenericDef.E_FPPIWIPEQ_INVALID_NX_PROCESS;
import static com.dx.mes.common.bean.def.GenericDef.E_FPPIWIPEQ_NO_WIP;
import static com.dx.mes.common.bean.def.GenericDef.PATH_TYPE_REWK;
import static com.dx.mes.common.bean.def.GenericDef.PROC_EMPTY;
import static com.dx.mes.common.bean.def.GenericDef.PROC_IN_PROCESS;
import static com.dx.mes.common.bean.def.GenericDef.PROC_WAIT;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_CODE_OK;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_CODE_SET_ERROR;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_CODE_UNKNOWN;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_MESG_OK;
import static com.dx.mes.common.bean.def.GenericDef.TRX_OUT;
import static com.dx.mes.common.bean.def.GenericDef._NO;
import static com.dx.mes.common.bean.def.GenericDef._NORMAL;
import static com.dx.mes.common.bean.def.GenericDef._SPACE;
import static com.dx.mes.common.bean.def.GenericDef._YES;
import static com.dx.mes.common.bean.def.GenericDef.T_FPPIWIPEQ;
import static com.dx.mes.common.bean.def.GenericDef.E_BIS_DATA;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dx.common.table.ppt.Bis_data;
import com.dx.common.table.ppt.Bis_ope;
import com.dx.common.table.ppt.Bis_opeId;
import com.dx.common.table.ppt.Bis_pathi;
import com.dx.common.table.ppt.Bis_pathiId;
import com.dx.common.table.ppt.Ret_box;
import com.dx.common.table.ppt.Ret_prd_info;
import com.dx.common.table.ppt.Ret_wo;
import com.dx.mes.common.dao.IBisDataDao;
import com.dx.mes.common.dao.IBisOpeDao;
import com.dx.mes.common.dao.IBisPathiDao;
import com.dx.mes.common.dao.IBisToolDao;
import com.dx.mes.common.dao.IRetBoxDao;
import com.dx.mes.common.dao.IRetPrdInfoDao;
import com.dx.mes.common.dao.IRetWODao;
import com.dx.mes.common.table.rtnBean.BoxInfoBeen;
import com.dx.mes.common.table.rtnBean.NotFoundRtnBeen;
import com.dx.mes.common.table.rtnBean.SimpleRtnBeen;
import com.dx.mes.common.transcoder.util.AppContext;
import com.dx.mes.common.transcoder.util.JacksonUtil;
import com.dx.mes.common.transcoder.util.LogUtils;
import com.dx.mes.common.transcoder.util.Util;
import com.dx.mes.facade.process.service.IFppiwipeqService;
import com.dx.mes.facade.process.tx.Fbpwipeq.FppwipeqI;
import com.dx.mes.facade.process.tx.Fbpwipeq.FppwipeqO;
import com.dx.mes.facade.process.tx.Fbpwipeq.FppwipeqOA;
import com.dx.mes.facade.process.tx.Fbpwipeq.FppwipeqOA2;


@Service("fppiwipeqService")
public class FppiwipeqService implements IFppiwipeqService{
	private LogUtils logUtils;

	@Autowired
	private IBisToolDao bisToolDao;
	@Autowired
	private IRetBoxDao retBoxDao;
	@Autowired
	private IRetPrdInfoDao retPrdInfoDao;
	@Autowired
	private IBisOpeDao bisOpeDao;
	@Autowired
	private IBisDataDao bisDataDao;
	@Autowired
	private IRetWODao retWoDao;
	@Autowired
	private IBisPathiDao bisPathiDao;
	
	public String subMainProc(String evt_no,String strInMsg) {
		AppContext.clear();
		AppContext.setCurrServiceName(FppiwipeqService.class.getSimpleName());
		AppContext.setCurrEventNumber(evt_no);
		logUtils = new LogUtils(FppiwipeqService.class);
		logUtils.info("[InTrx:" + strInMsg + "]");
		
		String strOutMsg = null;
		FppwipeqI inTrx = new FppwipeqI();
		FppwipeqO outTrx = new FppwipeqO();
		
		Session session = retBoxDao.getCrSession();
		
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
		try {
			inTrx = JacksonUtil.fromJson(strInMsg, FppwipeqI.class);

			char action_flg = inTrx.getAction_flg().charAt(0);
			
			/**
			 * 获取proc_id
			 */
			String ope_id = inTrx.getCr_ope_id();
			String ope_ver = inTrx.getCr_ope_ver();
			if (Util.isSpaceCheck(ope_id)) {
				outTrx.setRtn_code(RETURN_CODE_OK);
				outTrx.setRtn_mesg(RETURN_MESG_OK);
			}else{
				Bis_opeId bis_opeId = new Bis_opeId();
				bis_opeId.setOpe_id(ope_id);
				bis_opeId.setOpe_ver(ope_ver);
				
				Bis_ope bis_ope = new Bis_ope();
				bis_ope = bisOpeDao.get(bis_opeId);
				
				String hql = "FROM Bis_data WHERE data_cate = 'PRST' AND data_id = '" +bis_ope.getProc_id() + "'";
				
				List<Bis_data> bisDataList = new ArrayList<Bis_data>();
				bisDataList = bisDataDao.find(hql);
				if (bisDataList.isEmpty()) {
					outTrx.setRtn_code(E_BIS_DATA + E_READ_NOT_FOUND + "");
					outTrx.setRtn_mesg("该站点["+ope_id+"]制程段信息维护不全");
				}else{
					
					switch (action_flg) {
					case ACTION_FLG_INQUIRE: {
						outTrx = getWaitBoxList(inTrx);
						break;
					}
					case 'S': {
						outTrx = getInprPrdList(inTrx);
						break;
					}
					case 'B': {// 根据入账箱号获取产品信息
						outTrx = getBoxAndPrdList(inTrx);
						break;
					}
					case 'P': {// 根据转入箱号获取 INPR 产品信息
						outTrx = getInprPrdListByPrdInbox(inTrx);
						break;
					}
					case 'A': {// 查询在制的WAIT&INPR产品信息
						outTrx = getPrdList(inTrx);
						break;
					}
					default:
						outTrx = errActionFnc();
					}
				}
			}
			
			if (RETURN_CODE_OK.equals(outTrx.getRtn_code())) {
				session.flush();
			} else {
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			}
			
		} catch (Exception ex) {
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			outTrx.setRtn_mesg(ex.getCause().toString());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		} finally {
			strOutMsg = JacksonUtil.toJSONStr(outTrx);
			logUtils.info("[OutTrx:" + strOutMsg + "]");
		}
		return strOutMsg;
	}

	/**
	 * Get box List WAIT
	 * 
	 * @return
	 */
	private FppwipeqO getWaitBoxList(FppwipeqI inTrx) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		List<FppwipeqOA> oaryList = new ArrayList<FppwipeqOA>();
		List<BoxInfoBeen> boxInfoBeenList = new ArrayList<BoxInfoBeen>();
		
		// Tool group info
		String toolGId = "";
		rtnBeen = getToolgId(inTrx.getCr_ope_id(), inTrx.getCr_ope_ver());
		if (rtnBeen.getlRc() != _NORMAL) {
			outTrx.setRtn_code(rtnBeen.getlRc() + "");
			outTrx.setRtn_mesg(rtnBeen.getMsgBuf());
			return outTrx;
		} else {
			toolGId = (String) rtnBeen.getObj();
		}

		boxInfoBeenList = retBoxDao.retBox2BoxInfoByManyCondition(inTrx.getBox_id(),
				PROC_WAIT, toolGId, inTrx.getWo_id(), inTrx.getLot_id());
		if (!boxInfoBeenList.isEmpty()) {
			for (BoxInfoBeen box : boxInfoBeenList) {
				//增加厂别及线别的判定
				List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
				String sql = "FROM Ret_prd_info WHERE  prd_stat='WAIT' AND box_id_fk='"	+ box.getBox_id()	+ "'";
				ret_prd_infoList = retPrdInfoDao.find(sql);
				if (ret_prd_infoList.isEmpty()){
					continue;
				}
				FppwipeqOA FppwipeqOA = new FppwipeqOA();
				FppwipeqOA.setBox_id(box.getBox_id());
				FppwipeqOA.setMdl_id(box.getMdl_id_fk());
				FppwipeqOA.setOpe_id(box.getNx_ope_id_fk());
				FppwipeqOA.setPath_id(box.getNx_path_id_fk());
				FppwipeqOA.setPrty(box.getPrty());
				FppwipeqOA.setPrd_qty(Integer.toString(box.getPrd_qty()));
				FppwipeqOA.setWo_id(box.getWo_id());
				FppwipeqOA.setPrd_grade(box.getPrd_grade_fk());
				FppwipeqOA.setLot_id(box.getLot_id());
				FppwipeqOA.setMtrl_prod_id(box.getMtrl_prod_id());

				oaryList.add(FppwipeqOA);
			}
		}
		outTrx.setOary(oaryList);
		outTrx.setTbl_cnt(oaryList.size());
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	/**
	 * Get tool group info by tool id
	 * 
	 * @param ope_id
	 * @param ope_ver
	 * @return SimpleRtnBeen {String}
	 */
	private SimpleRtnBeen getToolgId(String ope_id, String ope_ver) {
		String gszMsgBuf = "";
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(ope_id);
		bis_opeId.setOpe_ver(ope_ver);

		bis_ope = bisOpeDao.get(bis_opeId);
		if (bis_ope == null) {
			gszMsgBuf = new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
					.toString();
			return new SimpleRtnBeen(E_BIS_TOOL_GR + E_READ_NOT_FOUND, gszMsgBuf);
		}

		return new SimpleRtnBeen(bis_ope.getToolg_id_fk());
	}
	
	/**
	 * Get INPR prd list
	 * 
	 * @return
	 */
	private FppwipeqO getInprPrdList(FppwipeqI inTrx) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		
		List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
		// Get Pep_lvl
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(inTrx.getCr_ope_id());
		bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		bis_ope = bisOpeDao.get(bis_opeId);
		if (null == bis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg( new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class).toString());
			return outTrx;
		}

		// Get prd list
		List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
		String sql = "FROM Ret_prd_info WHERE   prd_stat='INPR' AND (box_id_fk is null or box_id_fk='') AND cr_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND cr_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver() + "'";
		if (!Util.isSpaceCheck(inTrx.getTool_id())) {
			sql = sql + " AND cr_tool_id_fk='" + inTrx.getTool_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getWo_id())) {
			sql = sql + " AND wo_id_fk='" + inTrx.getWo_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
			sql = sql + " AND prd_seq_id='" + inTrx.getPrd_id() + "'";
		}

		ret_prd_infoList = retPrdInfoDao.find(sql);
		if (!ret_prd_infoList.isEmpty()) {
			for (Ret_prd_info prd : ret_prd_infoList) {
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setBox_id(prd.getBox_id_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				
				if(prd.getLogon_timestamp() != null){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
    				FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }

				oary_prd.add(FppwipeqOA2);
			}

		}
		outTrx.setOary_prd(oary_prd);
		outTrx.setTbl_cnt(oary_prd.size());
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	/**
	 * Get box and prd Info
	 * 
	 * @return
	 */
	private FppwipeqO getBoxAndPrdList(FppwipeqI inTrx) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		
		List<FppwipeqOA> oaryList = new ArrayList<FppwipeqOA>();
		/**
		 * 获取箱子信息
		 */
		Ret_box gRet_box = new Ret_box();
		gRet_box = retBoxDao.get(inTrx.getBox_id());
		if (gRet_box == null) {
			outTrx.setRtn_code(E_RET_BOX + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(inTrx.getBox_id(), Ret_box.class)
			.toString());
			return outTrx;
		}
		// Get intrx ope info
		Bis_ope gBis_ope = new Bis_ope();
		Bis_opeId gBis_opeId = new Bis_opeId();
		gBis_opeId.setOpe_id(inTrx.getCr_ope_id());
		gBis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		gBis_ope = bisOpeDao.get(gBis_opeId);
		if (null == gBis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(gBis_opeId.toString(),
					Bis_ope.class).toString());
			return outTrx;
		}
		if (!PROC_WAIT.equals(gRet_box.getBox_stat())
				&& !PROC_EMPTY.equals(gRet_box.getBox_stat())) {
			outTrx.setRtn_code(E_FPPIWIPEQ_INVALID_BOX_STAT + "");
			outTrx.setRtn_mesg("箱子的状态[" + gRet_box.getBox_stat()
					+ "]不正确,必须为等待入账或者已入账状态,请确认！");
			return outTrx;
		}
		if (!Util.isSpaceCheck(gRet_box.getNx_ope_id_fk())
				&& !Util.isSpaceCheck(gRet_box.getNx_ope_ver_fk())
				&& PROC_WAIT.equals(gRet_box.getBox_stat())) {
			// Get box ope info
			Bis_ope bis_ope = new Bis_ope();
			Bis_opeId bis_opeId = new Bis_opeId();
			bis_opeId.setOpe_id(gRet_box.getNx_ope_id_fk());
			bis_opeId.setOpe_ver(gRet_box.getNx_ope_ver_fk());

			bis_ope = bisOpeDao.get(bis_opeId);
			if (null == bis_ope) {
				outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
				outTrx.setRtn_mesg(new NotFoundRtnBeen(bis_opeId.toString(),
						Bis_ope.class).toString());
				return outTrx;
			}
			if (!gRet_box.getNx_ope_id_fk().equals(inTrx.getCr_ope_id())
					|| !gRet_box.getNx_ope_ver_fk().equals(
							inTrx.getCr_ope_ver())) {
				outTrx.setRtn_code(E_FPPIWIPEQ_INVALID_NX_PROCESS + "");
				outTrx.setRtn_mesg("箱子下一制程为[" + bis_ope.getOpe_dsc() + "],请确认！");
				return outTrx;
			}
		}
		FppwipeqOA FppwipeqOA = new FppwipeqOA();
		FppwipeqOA.setBox_id(gRet_box.getBox_id());
		FppwipeqOA.setBox_stat(gRet_box.getBox_stat());
		FppwipeqOA.setOpe_id(gRet_box.getNx_ope_id_fk());
		FppwipeqOA.setOpe_ver(gRet_box.getNx_ope_ver_fk());
		oaryList.add(FppwipeqOA);
		outTrx.setOary(oaryList);

		/**
		 * 获取产品信息
		 */
		List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
		String sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
			+ inTrx.getCr_ope_id()
			+ "' AND cr_ope_ver_fk = '"
			+ inTrx.getCr_ope_ver()
			+ "' AND pv_box_id_fk='" + inTrx.getBox_id() 
			+ "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
			+ inTrx.getCr_ope_id()
			+ "' AND nx_ope_ver_fk = '"
			+ inTrx.getCr_ope_ver() 
			+ "' AND box_id_fk='" + inTrx.getBox_id() + "'))";
		sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";
		ret_prd_infoList = retPrdInfoDao.find(sql);
		if (!ret_prd_infoList.isEmpty()) {
			List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
			for (Ret_prd_info prd : ret_prd_infoList) {
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
				if(ret_wo == null){
					FppwipeqOA2.setCus_id("");
				}else{
					FppwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
				}
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(gBis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
    				FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }

				oary_prd.add(FppwipeqOA2);
			}
			outTrx.setOary_prd(oary_prd);
			outTrx.setTbl_cnt(oary_prd.size());
		} else if (PROC_EMPTY.equals(gRet_box.getBox_stat())) {
			outTrx.setRtn_code(E_FPPIWIPEQ_NO_WIP + "");
			outTrx.setRtn_mesg("入账箱号在当前站点[" + gBis_ope.getOpe_dsc() + "]未找到WIP信息,请确认！");
			return outTrx;
		}

		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	/**
	 * 根据转入箱号获取 INPR 产品信息
	 * 
	 * @return
	 */
	private FppwipeqO getInprPrdListByPrdInbox(FppwipeqI inTrx) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		
		// Get Pep_lvl
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(inTrx.getCr_ope_id());
		bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		bis_ope = bisOpeDao.get(bis_opeId);
		if (null == bis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class).toString());
			return outTrx;
		}

		// Get prd list
		List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
		String sql = "FROM Ret_prd_info WHERE  prd_stat='INPR' AND cr_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND cr_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver() + "'";
		if (!Util.isSpaceCheck(inTrx.getBox_id())) {
			sql = sql + " AND box_id_fk='" + inTrx.getBox_id() + "'";
		}
		sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

		ret_prd_infoList = retPrdInfoDao.find(sql);
		outTrx.setTbl_cnt(0);
		if (!ret_prd_infoList.isEmpty()) {
			List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
			for (Ret_prd_info prd : ret_prd_infoList) {
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setBox_id(prd.getBox_id_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
//				if(null != prd.getPrd_admin_flg()){
//					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
//					String ipqc_flg = "OK";
//					String th_judge_flg = "OK";
//					String fz_flg = "OK";
//					if (prd_admin_flg_sb.charAt(1) == 'Y') {
//						ipqc_flg = "NG";
//					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
//						ipqc_flg = "OK";
//					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
//						ipqc_flg = "SC";
//					}else {
//						ipqc_flg = "";
//					}
//					if (prd_admin_flg_sb.charAt(2) == 'Y'){
//						th_judge_flg = "NG";
//					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
//						th_judge_flg = "OK";
//					}else {
//						th_judge_flg = "";
//					}
//					if (prd_admin_flg_sb.charAt(3) == 'Y'){
//						fz_flg = "NG";
//					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
//						fz_flg = "OK";
//					}else {
//						fz_flg = "";
//					}
//					FppwipeqOA2.setIpqc_flg(ipqc_flg);
//				}else {
//					FppwipeqOA2.setIpqc_flg("");
//				}
				
				if(prd.getLogon_timestamp() != null){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
    				FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				oary_prd.add(FppwipeqOA2);
			}
			outTrx.setOary_prd(oary_prd);
			outTrx.setTbl_cnt(oary_prd.size());
		}
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	/**
	 * Get WAIT&INPR prd list
	 * 
	 * @return
	 */
	private FppwipeqO getPrdList(FppwipeqI inTrx) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		// Get Pep_lvl
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(inTrx.getCr_ope_id());
		bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		bis_ope = bisOpeDao.get(bis_opeId);
		if (null == bis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class)
			.toString());
			return outTrx;
		}

		// Get prd list
		List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();

		String sql="";
		
		if (!Util.isSpaceCheck(inTrx.getBox_id())) {
			sql = "FROM Ret_prd_info WHERE  prd_stat='INPR' AND cr_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND cr_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver() 
				+ "' AND box_id_fk='" 
				+ inTrx.getBox_id() + "'";
		}else  if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
			sql = "FROM Ret_prd_info WHERE  ((prd_stat='INPR' AND cr_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND cr_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver()
				+ "' AND pv_box_id_fk='" + inTrx.getPv_box_id() 
				+ "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND nx_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver() 
				+ "' AND box_id_fk='" + inTrx.getPv_box_id() + "'))";
		}else{
			sql = "FROM Ret_prd_info WHERE  ((prd_stat='INPR' AND cr_ope_id_fk='"
					+ inTrx.getCr_ope_id()
					+ "' AND cr_ope_ver_fk = '"
					+ inTrx.getCr_ope_ver()
					+ "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
					+ inTrx.getCr_ope_id()
					+ "' AND nx_ope_ver_fk = '"
					+ inTrx.getCr_ope_ver() + "'))";
		}
		
		if (!Util.isSpaceCheck(inTrx.getWo_id())) {
			sql = sql + " AND wo_id_fk='" + inTrx.getWo_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getLot_id())) {
			sql = sql + " AND lot_id='" + inTrx.getLot_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
			sql = sql + " AND prd_seq_id='" + inTrx.getPrd_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
			sql = sql + " AND mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
		}
		
		sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

		ret_prd_infoList = retPrdInfoDao.find(sql);
		outTrx.setTbl_cnt(0);
		if (!ret_prd_infoList.isEmpty()) {
			List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
			for (Ret_prd_info prd : ret_prd_infoList) {
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
				if(ret_wo == null){
					FppwipeqOA2.setCus_id("");
				}else{
					FppwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
				}
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				String pathId = PROC_WAIT.equals(prd.getPrd_stat()) ? prd.getNx_path_id_fk() : prd.getCr_path_id_fk();
				String pathVer = PROC_WAIT.equals(prd.getPrd_stat()) ? prd.getNx_path_ver_fk() : prd.getCr_path_ver_fk();
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				//增加返工品标识
				Bis_pathiId id = new Bis_pathiId();
				id.setPath_id(pathId);
				id.setPath_ver(pathVer);
				Bis_pathi bis_pathi = bisPathiDao.get(id);
				if(bis_pathi !=null){
					if(bis_pathi.getPath_cate().equals(PATH_TYPE_REWK)){
						FppwipeqOA2.setOqc_skip_flg(_YES);
					}else{
						FppwipeqOA2.setOqc_skip_flg(_NO);
					}
				}
				
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
    				FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				
				oary_prd.add(FppwipeqOA2);
			}
			outTrx.setOary_prd(oary_prd);
			outTrx.setTbl_cnt(oary_prd.size());
		}

		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	
	
	private FppwipeqO getPrdWipWaitJBList(FppwipeqI inTrx, String gproc_flg) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		// Get Pep_lvl
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(inTrx.getCr_ope_id());
		bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		bis_ope = bisOpeDao.get(bis_opeId);
		if (null == bis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class).toString());
			return outTrx;
		}

		// Get prd list
		List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();

		String sql = "SELECT a.mtrl_box_id_fk, COUNT(a.prd_seq_id) ,b.prd_proc_qty FROM RET_PRD_INFO a "+ 
					  "LEFT JOIN RET_PRD_IN b ON a.mtrl_box_id_fk = b.mtrl_box_id "+
					  "WHERE a.cr_ope_id_fk = '"+
					  inTrx.getCr_ope_id()+"'"+
					  "AND a.cr_ope_ver_fk = '"+
					  inTrx.getCr_ope_ver()+"'"+ 
					  "AND a.prd_stat = 'INPR'";
		
		String hql = "FROM Ret_prd_info where prd_stat = 'WAIT' " + 
					 "AND nx_ope_id_fk = '" + 
					 inTrx.getCr_ope_id()+"'" +
					 "AND nx_ope_ver_fk = '" +
					 inTrx.getCr_ope_ver() + "'";
		
		if (!Util.isSpaceCheck(inTrx.getBox_id())) {
			sql = sql + " AND a.box_id_fk='" + inTrx.getBox_id() + "'";
			hql = hql + " AND box_id_fk='" + inTrx.getBox_id() + "'";
		}else  if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
			sql = sql +" AND a.pv_box_id_fk='" + inTrx.getPv_box_id() + "'";
			hql = hql +" AND box_id_fk='" + inTrx.getPv_box_id() + "'";
		}		
		if (!Util.isSpaceCheck(inTrx.getWo_id())) {
			sql = sql + " AND a.wo_id_fk='" + inTrx.getWo_id() + "'";
			hql += "AND wo_id_fk = '" + inTrx.getWo_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getLot_id())) {
			sql = sql + " AND a.lot_id='" + inTrx.getLot_id() + "'";
			hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
			sql = sql + " AND a.prd_seq_id='" + inTrx.getPrd_id() + "'";
			hql += "AND prd_seq_id = '" + inTrx.getPrd_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
			sql = sql + " AND a.mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
			hql += "AND mtrl_box_id_fk = '" + inTrx.getMtrl_box_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getLot_id())) {
			hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
		}
		
		sql = sql + " group by a.mtrl_box_id_fk";
		hql += " order by box_id_fk,convert(slot_no,UNSIGNED)";

		List<Object> list = retPrdInfoDao.findBySQL(sql);
		outTrx.setTbl_cnt(0);
		List<Ret_prd_info> ret_prd_info_list1 = new ArrayList<Ret_prd_info>();
		List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
		if (!list.isEmpty()) {
			for (int i=0;i<list.size();i++){
				Object[] obj = (Object[])list.get(i);	
				Ret_prd_info ret_prd_info = new Ret_prd_info();
				if ((_YES).equals(inTrx.getCheck_flg())){
					if(obj[2] == null){
						continue;
					}
					if (Integer.parseInt(obj[1].toString()) != Integer.parseInt(obj[2].toString())){
						ret_prd_info.setMtrl_box_id_fk(obj[0].toString());
						ret_prd_info_list1.add(ret_prd_info);
					}
				}else {
					if(obj[2] == null){
						continue;
					}
					if (Integer.parseInt(obj[1].toString()) == Integer.parseInt(obj[2].toString())){
						ret_prd_info.setMtrl_box_id_fk(obj[0].toString());
						ret_prd_info_list1.add(ret_prd_info);
					}
				}
				
			}
			String sql1 = "FROM Ret_prd_info where ( 1=0 ";
			for (Ret_prd_info prd:ret_prd_info_list1){
				sql1 = sql1 + "OR mtrl_box_id_fk = '" + prd.getMtrl_box_id_fk()+"'";
			}
			sql1 += ")";
			if (!Util.isSpaceCheck(inTrx.getBox_id())) {
				sql1 += "AND box_id_fk = '" + inTrx.getBox_id() + "'";
			}
			if (!Util.isSpaceCheck(inTrx.getLot_id())) {
				sql1 += "AND lot_id = '" + inTrx.getLot_id() + "'";
			}
			if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
				sql1 += "AND pv_box_id_fk = '" + inTrx.getPv_box_id() + "'";
			}
			sql1 = sql1 + 
				  "AND cr_ope_id_fk = '"+
				  inTrx.getCr_ope_id()+"'"+
				  "AND cr_ope_ver_fk = '"+
				  inTrx.getCr_ope_ver()+"'"+
				  "AND prd_stat = 'INPR'" + 
				  "order by pv_box_id_fk,convert(slot_no,UNSIGNED)";
			
			List<Ret_prd_info>  ret_prd_info_list =  new ArrayList<Ret_prd_info>();
			ret_prd_info_list = retPrdInfoDao.find(sql1);
			
			for(Ret_prd_info prd : ret_prd_info_list){
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
				if(ret_wo == null){
					FppwipeqOA2.setCus_id("");
				}else{
					FppwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
				}
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				if (!Util.isSpaceCheck(gproc_flg)) {
					FppwipeqOA2.setProc_flg(gproc_flg);
				}
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
    				FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				
				oary_prd.add(FppwipeqOA2);
			}
		}
		
		if ((_NO).equals(inTrx.getCheck_flg())){
			List<Ret_prd_info> ret_prd_info_wait_list = new ArrayList<Ret_prd_info>();
			ret_prd_info_wait_list = retPrdInfoDao.find(hql);
			for(Ret_prd_info prd : ret_prd_info_wait_list){
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				if (!Util.isSpaceCheck(gproc_flg)) {
					FppwipeqOA2.setProc_flg(gproc_flg);
				}
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
    				FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				oary_prd.add(FppwipeqOA2);
			}
		}
		
		outTrx.setOary_prd(oary_prd);
		outTrx.setTbl_cnt(oary_prd.size());
		
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	private FppwipeqO getPrdWipWaitDMList(FppwipeqI inTrx, String gproc_flg) {
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		// Get Pep_lvl
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(inTrx.getCr_ope_id());
		bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		bis_ope = bisOpeDao.get(bis_opeId);
		if (null == bis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class).toString());
			return outTrx;
		}

		String sql = "SELECT a.LOT_ID,COUNT(a.prd_seq_id) ,b.LOT_QTY FROM RET_PRD_INFO a "+
					  "LEFT JOIN RET_PRD_LOT b ON a.LOT_ID = b.LOT_ID "+
					  "WHERE a.cr_ope_id_fk = '"+
					  inTrx.getCr_ope_id()+"'"+
					  "AND a.cr_ope_ver_fk = '"+
					  inTrx.getCr_ope_ver()+"'" + 
					  "AND a.prd_stat = 'INPR'";
		
		String hql = "FROM Ret_prd_info where prd_stat = 'WAIT' " + 
					 "AND nx_ope_id_fk = '" + 
					 inTrx.getCr_ope_id()+"'" +
					 "AND nx_ope_ver_fk = '" +
					 inTrx.getCr_ope_ver() + "'";	
		
		if (!Util.isSpaceCheck(inTrx.getBox_id())) {
			sql = sql + " AND a.box_id_fk='" + inTrx.getBox_id() + "'";
			hql = hql + " AND box_id_fk='" + inTrx.getBox_id() + "'";
		}else  if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
			sql = sql +" AND a.pv_box_id_fk='" + inTrx.getPv_box_id() + "'";
			hql = hql +" AND box_id_fk='" + inTrx.getPv_box_id() + "'";
		}		
		
		if (!Util.isSpaceCheck(inTrx.getWo_id())) {
			sql = sql + " AND a.wo_id_fk='" + inTrx.getWo_id() + "'";
			hql += "AND wo_id_fk = '" + inTrx.getWo_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getLot_id())) {
			sql = sql + " AND a.lot_id='" + inTrx.getLot_id() + "'";
			hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getPrd_id())) {
			sql = sql + " AND a.prd_seq_id='" + inTrx.getPrd_id() + "'";
			hql += "AND prd_seq_id = '" + inTrx.getPrd_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
			sql = sql + " AND a.mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
			hql += "AND mtrl_box_id_fk = '" + inTrx.getMtrl_box_id() + "'";
		}
		if (!Util.isSpaceCheck(inTrx.getLot_id())) {
			hql += "AND lot_id = '" + inTrx.getLot_id() + "'";
		}
		
		sql = sql + "GROUP BY a.LOT_ID ";
		hql += " order by box_id_fk, convert(slot_no,UNSIGNED)";

		List<Object> list = retPrdInfoDao.findBySQL(sql);
		outTrx.setTbl_cnt(0);
		List<Ret_prd_info> ret_prd_info_list1 = new ArrayList<Ret_prd_info>(); 
		List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
		
		if (!list.isEmpty()) {
			for (int i=0;i<list.size();i++){
				Object[] obj = (Object[])list.get(i);
				
				Ret_prd_info ret_prd_info = new Ret_prd_info();
				if ((_YES).equals(inTrx.getCheck_flg())){
					if(obj[2] == null){
						continue;
					}
					if (Integer.parseInt(obj[1].toString()) != Integer.parseInt(obj[2].toString())){
						ret_prd_info.setLot_id(obj[0].toString());
						ret_prd_info_list1.add(ret_prd_info);
					}
				}else {
					if(obj[2] == null){
						continue;
					}
					if (Integer.parseInt(obj[1].toString()) == Integer.parseInt(obj[2].toString())){
						ret_prd_info.setLot_id(obj[0].toString());
						ret_prd_info_list1.add(ret_prd_info);
					}
				}
				
			}
			
			/**
			 * 这里的1=0没有问题
			 * 解释:如果lot_id为空,那么不显示结果,所以加上1=0
			 */
			String sql1 = "FROM Ret_prd_info where  ( 1=0";
			for (Ret_prd_info prd:ret_prd_info_list1){
				sql1 = sql1 + " OR lot_id = '" + prd.getLot_id()+"'";
			}
			sql1 += ")";
			if (!Util.isSpaceCheck(inTrx.getBox_id())) {
				sql1 += "AND box_id_fk = '" + inTrx.getBox_id() + "'";
			}
			if (!Util.isSpaceCheck(inTrx.getLot_id())) {
				sql1 += "AND lot_id = '" + inTrx.getLot_id() + "'";
			}
			if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
				sql1 += "AND pv_box_id_fk = '" + inTrx.getPv_box_id() + "'";
			}
			if (!Util.isSpaceCheck(inTrx.getMtrl_box_id())) {
				sql1 += "AND mtrl_box_id_fk = '" + inTrx.getMtrl_box_id() + "'";
			}
			sql1 = sql1 +
			  "AND cr_ope_id_fk = '"+
			  inTrx.getCr_ope_id()+"'"+
			  "AND cr_ope_ver_fk = '"+
			  inTrx.getCr_ope_ver()+"'" +
			  "AND prd_stat = 'INPR'" +
			  "order by pv_box_id_fk,convert(slot_no,UNSIGNED)";
			
			List<Ret_prd_info>  ret_prd_info_list =  new ArrayList<Ret_prd_info>();
			ret_prd_info_list = retPrdInfoDao.find(sql1);
			
			for(Ret_prd_info prd : ret_prd_info_list){
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
				if(ret_wo == null){
					FppwipeqOA2.setCus_id("");
				}else{
					FppwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
				}
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				if (!Util.isSpaceCheck(gproc_flg)) {
					FppwipeqOA2.setProc_flg(gproc_flg);
				}
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
                	FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				
				oary_prd.add(FppwipeqOA2);
			}
		}
		
		if ((_NO).equals(inTrx.getCheck_flg())){
			List<Ret_prd_info> ret_prd_info_wait_list = new ArrayList<Ret_prd_info>();
			ret_prd_info_wait_list = retPrdInfoDao.find(hql);
			for(Ret_prd_info prd : ret_prd_info_wait_list){
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				if (!Util.isSpaceCheck(gproc_flg)) {
					FppwipeqOA2.setProc_flg(gproc_flg);
				}
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
                	FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				oary_prd.add(FppwipeqOA2);
			}
		}
		
		outTrx.setOary_prd(oary_prd);
		outTrx.setTbl_cnt(oary_prd.size());
		
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	
	private FppwipeqO queryPrdInfoByMtrlBox (FppwipeqI inTrx, String gproc_flg){
		FppwipeqO outTrx = new FppwipeqO();
		outTrx.setTrx_id(T_FPPIWIPEQ);
		outTrx.setType_id(TRX_OUT);
		// Get Pep_lvl
		Bis_ope bis_ope = new Bis_ope();
		Bis_opeId bis_opeId = new Bis_opeId();
		bis_opeId.setOpe_id(inTrx.getCr_ope_id());
		bis_opeId.setOpe_ver(inTrx.getCr_ope_ver());

		bis_ope = bisOpeDao.get(bis_opeId);
		if (null == bis_ope) {
			outTrx.setRtn_code(E_BIS_OPE + E_READ_NOT_FOUND + "");
			outTrx.setRtn_mesg(new NotFoundRtnBeen(bis_opeId.toString(), Bis_ope.class).toString());
			return outTrx;
		}

		// Get prd list
		List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();

		String sql="";
		
		if (!Util.isSpaceCheck(inTrx.getBox_id())) {
			sql = "FROM Ret_prd_info WHERE prd_stat='INPR' AND cr_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND cr_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver() 
				+ "' AND box_id_fk='" 
				+ inTrx.getBox_id() + "'";
		}else  if (!Util.isSpaceCheck(inTrx.getPv_box_id())) {
			sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND cr_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver()
				+ "' AND pv_box_id_fk='" + inTrx.getPv_box_id() 
				+ "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
				+ inTrx.getCr_ope_id()
				+ "' AND nx_ope_ver_fk = '"
				+ inTrx.getCr_ope_ver() 
				+ "' AND box_id_fk='" + inTrx.getPv_box_id() + "'))";
		}else{
			sql = "FROM Ret_prd_info WHERE ((prd_stat='INPR' AND cr_ope_id_fk='"
					+ inTrx.getCr_ope_id()
					+ "' AND cr_ope_ver_fk = '"
					+ inTrx.getCr_ope_ver()
					+ "') or (prd_stat='WAIT' AND nx_ope_id_fk='"
					+ inTrx.getCr_ope_id()
					+ "' AND nx_ope_ver_fk = '"
					+ inTrx.getCr_ope_ver() + "'))";
		}
		sql = sql + " AND mtrl_box_id_fk='" + inTrx.getMtrl_box_id() + "'";
		sql = sql + " ORDER BY box_id_fk,pv_box_id_fk, convert(slot_no,UNSIGNED) ";

		ret_prd_infoList = retPrdInfoDao.find(sql);
		outTrx.setTbl_cnt(0);
		if (!ret_prd_infoList.isEmpty()) {
			List<FppwipeqOA2> oary_prd = new ArrayList<FppwipeqOA2>();
			for (Ret_prd_info prd : ret_prd_infoList) {
				FppwipeqOA2 FppwipeqOA2 = new FppwipeqOA2();
				Ret_wo ret_wo = retWoDao.get(prd.getWo_id_fk());
				if(ret_wo == null){
					FppwipeqOA2.setCus_id("");
				}else{
					FppwipeqOA2.setCus_id(ret_wo.getCus_id_fk());
				}
				FppwipeqOA2.setPrd_seq_id(prd.getPrd_seq_id());
				FppwipeqOA2.setSlot_no(prd.getSlot_no());
				FppwipeqOA2.setMtrl_slot_no_fk(prd.getMtrl_slot_no_fk());
				FppwipeqOA2.setEvt_timestamp(prd.getEvt_timestamp().toString());
				FppwipeqOA2.setEvt_user(prd.getEvt_usr());
				FppwipeqOA2.setLot_id(prd.getLot_id());
				if( PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setPrd_grade(prd.getPrd_grade());
				}else{
					FppwipeqOA2.setPrd_grade(_SPACE);
				}
				FppwipeqOA2.setCr_proc(prd.getCr_proc_id_fk());
				FppwipeqOA2.setCr_ope_id(prd.getCr_ope_id_fk());
				FppwipeqOA2.setCr_ope_no_fk(prd.getCr_ope_no_fk());
				FppwipeqOA2.setCr_ope_ver_fk(prd.getCr_ope_ver_fk());
				FppwipeqOA2.setCr_path_id_fk(prd.getCr_path_id_fk());
				FppwipeqOA2.setCr_path_ver_fk(prd.getCr_path_ver_fk());
				FppwipeqOA2.setCr_tool_id_fk(prd.getCr_tool_id_fk());
				FppwipeqOA2.setFab_sn(prd.getFab_sn());
				FppwipeqOA2.setPep_lvl(bis_ope.getPep_lvl());
				FppwipeqOA2.setWo_id(prd.getWo_id_fk());
				FppwipeqOA2.setMdl_id_fk(prd.getMdl_id_fk());
				FppwipeqOA2.setPrd_qty(prd.getPrd_qty());
				FppwipeqOA2.setPrd_std_qty(prd.getPrd_std_qty());
				FppwipeqOA2.setSht_ope_msg(prd.getSht_ope_msg());
				FppwipeqOA2.setPrd_stat(prd.getPrd_stat());
				FppwipeqOA2.setPv_prd_grade(prd.getPv_prd_grade());
				FppwipeqOA2.setDs_recipe_id(prd.getDs_recipe_id());
				FppwipeqOA2.setGroup_id(prd.getGroup_id());
				if (!Util.isSpaceCheck(gproc_flg)) {
					FppwipeqOA2.setProc_flg(gproc_flg);
				}
				//增加返工品标识
				if(!Util.isSpaceCheck(prd.getOqc_skip_flg())){
					FppwipeqOA2.setOqc_skip_flg(prd.getOqc_skip_flg());
				}
				
				FppwipeqOA2.setPrd_admin_flg(prd.getPrd_admin_flg());
				if(null != prd.getPrd_admin_flg()){
					StringBuffer prd_admin_flg_sb = new StringBuffer(prd.getPrd_admin_flg());
					String ipqc_flg = "OK";
					String th_judge_flg = "OK";
					String fz_flg = "OK";
					if (prd_admin_flg_sb.charAt(1) == 'Y') {
						ipqc_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(1) == 'N') {
						ipqc_flg = "OK";
					}else if (prd_admin_flg_sb.charAt(1) == 'S'){
						ipqc_flg = "SC";
					}else {
						ipqc_flg = "";
					}
					if (prd_admin_flg_sb.charAt(2) == 'Y'){
						th_judge_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(2) == 'N') {
						th_judge_flg = "OK";
					}else {
						th_judge_flg = "";
					}
					if (prd_admin_flg_sb.charAt(3) == 'Y'){
						fz_flg = "NG";
					}else if (prd_admin_flg_sb.charAt(3) == 'N') {
						fz_flg = "OK";
					}else {
						fz_flg = "";
					}
					FppwipeqOA2.setIpqc_flg(ipqc_flg);
				}else {
					FppwipeqOA2.setIpqc_flg("");
				}
				
				if(PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id(prd.getBox_id_fk());
					FppwipeqOA2.setPv_box_id_fk(prd.getPv_box_id_fk());
				}else if(PROC_WAIT.equals(prd.getPrd_stat())){
					FppwipeqOA2.setBox_id("");
					FppwipeqOA2.setPv_box_id_fk(prd.getBox_id_fk());
				}
				FppwipeqOA2.setMtrl_box_id_fk(prd.getMtrl_box_id_fk());
				FppwipeqOA2.setX_axis_cnt_fk(prd.getX_axis_cnt_fk());
				FppwipeqOA2.setY_axis_cnt_fk(prd.getY_axis_cnt_fk());
				if(prd.getLogon_timestamp() != null && PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					FppwipeqOA2.setLogon_usr(prd.getLogon_usr());
					FppwipeqOA2.setLogon_timestamp(prd.getLogon_timestamp().toString());
				}
                if(prd.getLogof_timestamp() != null){
                	FppwipeqOA2.setLogof_usr(prd.getLogof_usr());
    				FppwipeqOA2.setLogof_timestamp(prd.getLogof_timestamp().toString());
                }
				
				oary_prd.add(FppwipeqOA2);
			}
			outTrx.setOary_prd(oary_prd);
			outTrx.setTbl_cnt(oary_prd.size());
		}

		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return outTrx;
	}
	
	public FppwipeqO errActionFnc() {
		FppwipeqO FppwipeqO = new FppwipeqO();
		FppwipeqO.setRtn_code(E_FPPIWIPEQ_INVALID_INPUT + "");
		FppwipeqO.setRtn_mesg("Invalid Action_flg");
		return FppwipeqO;
	}
}
